package com.huike.ycu.mybatis.service.impl;

import com.huike.ycu.mybatis.mapper.UmsAdminDao;
import com.huike.ycu.mybatis.model.UmsAdmin;
import com.huike.ycu.mybatis.result.CodeMsg;
import com.huike.ycu.mybatis.result.Result;
import com.huike.ycu.mybatis.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

@Service
public class AdminServiceImpl implements AdminService {
    @Autowired
    private UmsAdminDao adminDao;

    @Override
    public UmsAdmin login(UmsAdmin umsAdmin) {
        return adminDao.selectByUsernameAndPassword(umsAdmin);
    }

    @Override
    public Result<UmsAdmin> login01(UmsAdmin umsAdmin) {
        UmsAdmin admin = this.adminDao.selectByUsernameAndPassword(umsAdmin);

        if(ObjectUtils.isEmpty(admin)) {
            return Result.error(CodeMsg.USERNAME_PASSWORD_ERROR);
        }
        return Result.success(admin);
    }


    @Override
    public int register(UmsAdmin umsAdmin) {

        return adminDao.insertSelective(umsAdmin);
    }


}
